home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / ToolManager / Source / Library / global.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  4KB  |  129 lines

  1. /*
  2.  * global.c  V3.1
  3.  *
  4.  * ToolManager global parameters
  5.  *
  6.  * Copyright (C) 1990-98 Stefan Becker
  7.  *
  8.  * This source code is for educational purposes only. You may study it
  9.  * and copy ideas or algorithms from it for your own projects. It is
  10.  * not allowed to use any of the source codes (in full or in parts)
  11.  * in other programs. Especially it is not allowed to create variants
  12.  * of ToolManager or ToolManager-like programs from this source code.
  13.  *
  14.  */
  15.  
  16. #include "toolmanager.h"
  17.  
  18. /* Local data */
  19. #define PROPCHUNKS 3
  20. static const ULONG PropChunksTable[2 * PROPCHUNKS] = {
  21.  ID_TMGP, ID_DATA,
  22.  ID_TMGP, ID_CDIR,
  23.  ID_TMGP, ID_CMND
  24. };
  25. static const ULONG MapRemapPrecision[DATA_GLOBAL_PRECISION_MAX] = {
  26.  PRECISION_EXACT, PRECISION_IMAGE, PRECISION_ICON, PRECISION_GUI
  27. };
  28. static char *GlobalDirectory   = NULL;
  29. static char *GlobalPreferences = NULL;
  30.  
  31. /* Parse global parameters IFF chunk */
  32. #undef  DEBUGFUNCTION
  33. #define DEBUGFUNCTION ParseGlobalIFF
  34. BOOL ParseGlobalIFF(struct IFFHandle *iffh)
  35. {
  36.  BOOL rc = FALSE;
  37.  
  38.  GLOBAL_LOG(LOG1(Handle, "0x%08lx", iffh))
  39.  
  40.  /* Configure & start IFF parser */
  41.  if ((PropChunks(iffh, PropChunksTable, PROPCHUNKS) == 0) &&
  42.      (StopOnExit(iffh, ID_TMGP, ID_FORM) == 0)  &&
  43.      (ParseIFF(iffh, IFFPARSE_SCAN) == IFFERR_EOC)) {
  44.   struct StoredProperty *sp;
  45.  
  46.   GLOBAL_LOG(LOG1(Parsed, "Data 0x%08lx", sp))
  47.  
  48.   /* Chunk parsed. First delete old global parameters */
  49.   FreeGlobalParameters();
  50.  
  51.   /* Duplicate strings */
  52.   GlobalDirectory   = DuplicateProperty(iffh, ID_TMGP, ID_CDIR);
  53.   GlobalPreferences = DuplicateProperty(iffh, ID_TMGP, ID_CMND);
  54.  
  55.   GLOBAL_LOG(LOG2(Directory, "%s (0x%08lx)",   GlobalDirectory,
  56.                   GlobalDirectory))
  57.   GLOBAL_LOG(LOG2(Preferences, "%s (0x%08lx)", GlobalPreferences,
  58.                   GlobalPreferences))
  59.  
  60.   /* Directory valid? */
  61.   if (GlobalDirectory)
  62.  
  63.    /* Yes, go to directory. This may fail but our directory is NULL anyway */
  64.    CurrentDir(Lock(GlobalDirectory, SHARED_LOCK));
  65.  
  66.   /* Does DATA chunk exist? */
  67.   if (sp = FindProp(iffh, ID_TMGP, ID_DATA)) {
  68.    struct GlobalDATAChunk *gdc = (struct GlobalDATAChunk *) sp->sp_Data;
  69.    ULONG                   i;
  70.  
  71.    GLOBAL_LOG(LOG2(Data, "Flags 0x%08lx Precision %ld", gdc->gdc_Flags,
  72.                    gdc->gdc_Precision))
  73.  
  74.    /* Network enabled or disabled? */
  75.    if (gdc->gdc_Flags & DATA_GLOBALF_NETWORKENABLE)
  76.     EnableNetwork();
  77.    else
  78.     DisableNetwork();
  79.  
  80.    /* Sanity check for remap precision */
  81.    if ((i = gdc->gdc_Precision) >= DATA_GLOBAL_PRECISION_MAX)
  82.     i = DATA_GLOBAL_PRECISION_DEFAULT;
  83.  
  84.    /* Remapping enabled? */
  85.    EnableRemap((gdc->gdc_Flags & DATA_GLOBALF_REMAPENABLE) != 0,
  86.                MapRemapPrecision[i]);
  87.   }
  88.  
  89.   /* Chunk OK */
  90.   rc = TRUE;
  91.  }
  92.  
  93.  GLOBAL_LOG(LOG1(Result, "%ld", rc))
  94.  
  95.  return(rc);
  96. }
  97.  
  98. #undef  DEBUGFUNCTION
  99. #define DEBUGFUNCTION FreeGlobalParameters
  100. /* Free global parameters */
  101. void FreeGlobalParameters(void)
  102. {
  103.  GLOBAL_LOG(LOG0(Freeing global data))
  104.  
  105.  /* Free strings */
  106.  if (GlobalPreferences) FreeVector(GlobalPreferences);
  107.  GlobalPreferences = NULL;
  108.  if (GlobalDirectory)   FreeVector(GlobalDirectory);
  109.  GlobalDirectory   = NULL;
  110.  
  111.  /* Return to NULL lock and release old directory (Maybe NULL!) */
  112.  UnLock(CurrentDir(NULL));
  113. }
  114.  
  115. /* Return name of global default directory */
  116. char *GetGlobalDefaultDirectory(void)
  117. {
  118.  return(GlobalDirectory ? GlobalDirectory : DefaultDirectory);
  119. }
  120.  
  121. /* Start preferences program */
  122. void StartPreferences(void)
  123. {
  124.  /* Start preferences as WB program */
  125.  StartWBProgram(GlobalPreferences ? GlobalPreferences :
  126.                                     "SYS:Prefs/ToolManager",
  127.                 GlobalDirectory, 4096, 0, NULL);
  128. }
  129.